package com.wao.cms.service;

import com.wao.cms.domain.Footer;
import com.wao.cms.repository.FooterRepository;
import com.wao.cms.service.dto.FooterDTO;
import com.wao.cms.service.mapper.FooterMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing Footer.
 */
@Service
@Transactional
public class FooterService {

    private final Logger log = LoggerFactory.getLogger(FooterService.class);

    private final FooterRepository footerRepository;

    private final FooterMapper footerMapper;

    public FooterService(FooterRepository footerRepository, FooterMapper footerMapper) {
        this.footerRepository = footerRepository;
        this.footerMapper = footerMapper;
    }

    /**
     * Save a footer.
     *
     * @param footerDTO the entity to save
     * @return the persisted entity
     */
    public FooterDTO save(FooterDTO footerDTO) {
        log.debug("Request to save Footer : {}", footerDTO);
        Footer footer = footerMapper.toEntity(footerDTO);
        footer = footerRepository.save(footer);
        return footerMapper.toDto(footer);
    }

    /**
     * Get all the footers.
     *
     * @param pageable the pagination information
     * @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<FooterDTO> findAll(Pageable pageable) {
        log.debug("Request to get all Footers");
        return footerRepository.findAll(pageable)
            .map(footerMapper::toDto);
    }

    /**
     * Get one footer by id.
     *
     * @param id the id of the entity
     * @return the entity
     */
    @Transactional(readOnly = true)
    public FooterDTO findOne(Long id) {
        log.debug("Request to get Footer : {}", id);
        Footer footer = footerRepository.findOne(id);
        return footerMapper.toDto(footer);
    }

    /**
     * Delete the  footer by id.
     *
     * @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Footer : {}", id);
        footerRepository.delete(id);
    }

    /**
     * Get Footers by Website.
     *
     * @param pageable  the pagination information
     * @param websiteId the id of the Website
     * @return the list of entities
     */
    @Transactional(readOnly = true)
    public Page<FooterDTO> findByWebsiteId(Long websiteId, Pageable pageable) {
        log.debug("Request to get Footers by Website: {}", websiteId);
        return footerRepository.findByWebsiteId(websiteId, pageable)
            .map(footerMapper::toDto);
    }
}
